<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核状态">
              <j-dict-select-tag placeholder="请选择审核状态" v-model="queryParam.auditStatus" dictCode="binding_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人ID">
              <a-input placeholder="请输入申请人ID" v-model="queryParam.applyUserId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="对方id">
              <a-input placeholder="请输入对方id" v-model="queryParam.bindUserId"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="申请时间">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" @click="batchAuditBinding(2)">批量通过</a-button>
      <a-button type="primary" @click="batchAuditBinding(3)">批量拒绝</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('绑定下级审核')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      &lt;!&ndash; 高级查询区域 &ndash;&gt;
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="statusSlot" slot-scope="text, record">
          <div v-if="record.auditStatus === '1'" style="color: #169bd5">{{text}}</div>
          <div v-else-if="record.auditStatus === '2'" style="color: #000000">{{text}}</div>
          <div v-else style="color: red">{{text}}</div>
        </template>
        <template slot="fileSlot" slot-scope="text,record">
          <a @click="() => viewFile(text)">查看</a>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-popconfirm v-if="record.auditStatus=='1'" title="确定审核通过吗?" @confirm="() => auditBinding(record.id,2)">
            <a>审核通过</a>
          </a-popconfirm>
          <a-divider type="vertical" v-if="record.auditStatus=='1'" />
          <a-popconfirm v-if="record.auditStatus=='1'" title="确定审核拒绝吗?" @confirm="() => auditBinding(record.id,3)">
            <a>审核拒绝</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <binding-audit-modal ref="modalForm" @ok="modalFormOk"></binding-audit-modal>
    <ViewFileModel ref="ViewFileModel"></ViewFileModel>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BindingAuditModal from './modules/BindingAuditModal'
  import { postAction } from '@/api/manage'
  import ViewFileModel from '@/views/xiny/common/ViewFileModel'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'BindingAuditList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BindingAuditModal,
      ViewFileModel
    },
    data () {
      return {
        description: '绑定下级审核管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },

          {
            title:'申请人ID',
            align:"center",
            dataIndex: 'applyUserId'
          },
          {
            title:'申请人昵称',
            align:"center",
            dataIndex: 'applyUserName'
          },
          {
            title:'对方ID',
            align:"center",
            dataIndex: 'bindUserId'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'文件地址',
            align:"center",
            dataIndex: 'fileUrl',
            scopedSlots: {customRender: 'fileSlot'}
          },
          {
            title:'审核状态',
            align:"center",
            dataIndex: 'auditStatus_dictText',
            scopedSlots: { customRender: 'statusSlot' }
          },
          {
            title:'申请时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/user/bindingAudit/list",
          delete: "/user/bindingAudit/delete",
          deleteBatch: "/user/bindingAudit/deleteBatch",
          exportXlsUrl: "/user/bindingAudit/exportXls",
          importExcelUrl: "user/bindingAudit/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    //this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //查看文件
      viewFile(fileUrl){
        if(fileUrl){
          this.$refs.ViewFileModel.fileUrl=fileUrl.split(",");
        }
        this.$refs.ViewFileModel.title="查看文件";
        this.$refs.ViewFileModel.visible=true;
      },

      //批量审核
      batchAuditBinding(auditStatus){
        var that=this;
        if(this.selectedRowKeys.length==0){
          this.$message.warning("请至少选择一条记录进行审核");
          return;
        }
        var ids = this.selectedRowKeys.join(",");

        this.auditBinding(ids,auditStatus);
      },

      //审核
      auditBinding(id,status){
        var that=this;
        this.loading = true;
        //如果是审核通过，需要检验用户是否存在上级
        /*if(status==2){
          this.$confirm('确定审核通过吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {

          }).catch(() => {

          });
        }*/

        postAction("/user/bindingAudit/auditBinding",{id:id,auditStatus:status}).then((res)=>{
          if(res.success){
            that.$message.success(res.message);
            this.loadData();
          }else{
            if(res.message == '您绑定的推荐人是您下级，不能绑定'){
              that.$message.warning("您绑定的下级是您的上级，不能绑定");
            }else{
              that.$message.warning(res.message);
            }

          }
        }).finally(() => {
          that.loading = false;
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>